<?php

//方法文件


/**
 * @param $weSql
 * @param $user
 */
function isUserBlack($weSql, $user){

    /**
     * @var $ADMIN_CONTACT
     */

    include "../WeSql/config.php";

    if($weSql->isSelectField("user_black",[
        'user' => $user
    ])){
        $result = [
            "code" => -1,
            "msg" => "该账号被拉黑中",
            "exception" => "请联系管理员：".$ADMIN_CONTACT
        ];
        exit(json_encode($result,JSON_UNESCAPED_UNICODE));
    }
}

function isIpBlack($weSql,$ip){

    /**
     * @var $ADMIN_CONTACT
     */

    include "../WeSql/config.php";

    if($weSql->isSelectField("ip_black",[
        'ip' => $ip
    ])){
        $result = [
            "code" => -1,
            "msg" => "该ip被拉黑中",
            "exception" => "请联系管理员：".$ADMIN_CONTACT
        ];
        exit(json_encode($result,JSON_UNESCAPED_UNICODE));
    }
}

function isUser($weSql,$user){

    include '../WeSql/config.php';
    /** @var WeSql $weSql */
    return (bool)$weSql->isSelectField('user',[
        'user' => $user
    ]);
}

function isPassWord($weSql,$user,$pass){
    /**
     * @var $key
     */

    include "../WeSql/config.php";
    if(decrypt($key,$weSql->select("user","user=${user}")['pass']) != $pass){
        $result = [
            "code" => -1,
            "msg" => "密码错误",
            "exception" => "密码错误"
        ];
        exit(json_encode($result,JSON_UNESCAPED_UNICODE));
    }
}

function isTime($time){
    /**
     * @var $OVERTIME_TIMN
     */
    include "../WeSql/config.php";
    if((time() - $time) * 1000 > $OVERTIME_TIMN or $time == ""){
        $result = [
            "code" => -1,
            "msg" => "意外错误",
            "exception" => "时间戳超时"
        ];
        exit(json_encode($result,JSON_UNESCAPED_UNICODE));
    }

}